package com.imm.controller;


import com.imm.common.Result;
import com.imm.pojo.AddressBook;
import com.imm.service.IAddressBookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Resource
    private IAddressBookService addressBookService;

    @GetMapping("/list")
    public Result<List<AddressBook>> list(AddressBook addressBook) {
        return addressBookService.listAddress(addressBook);
    }

    @PostMapping
    public Result<String> insert(@RequestBody AddressBook addressBook) {
        return addressBookService.insert(addressBook);
    }

    @PutMapping("/default")
    public Result<String> defaultAddressBook(@RequestBody AddressBook addressBook) {
        return addressBookService.defalut(addressBook);
    }


    @GetMapping("/default")
    public Result<AddressBook> defaultAddressBook() {
        return addressBookService.defalut();
    }

    @GetMapping("{id}")
    public Result<AddressBook> findOne(@PathVariable("id") Long id) {
        return addressBookService.findOne(id);
    }

    @PutMapping
    public Result<String> update(@RequestBody AddressBook addressBook) {
        return addressBookService.updateAddressBook(addressBook);
    }

    @DeleteMapping
    public Result<String> delete(Long ...ids) {
        return addressBookService.delete(ids);
    }

}
